$(function(){
	
	var courseState = ['开课提醒','作业已提交','作业已批改'];
	for(var i=0;i<courseState.length;i++){ $(".course_state_"+i).text(courseState[i]); };
	
	var timePoint = [ 
		'16:30', 
		'16:40', 
		'16:50', 
		'16:55', 
		'17:00', 
		'17:05', 
		'17:05', 
		'18:10', 
		'18:20', 
		'18:30', 
		'18:40', 
		'19:00', 
		'20:10', 
		'20:12', 
		'20:15', 
		'20:18', 
		'20:21', 
		'20:24', 
		'20:27', 
		'20:30',
	];
	for(var i=0;i<timePoint.length;i++){ $(".time_point_"+i).text(timePoint[i]); };
	
	
	var talkParent = [
		{'sort':'talk_other','profile':'teacher_l.jpg','content':'@all 这周的课外拓展作业是了解海洋动物，各位家长可以周末带孩子去海洋馆进行观察学习。'},
		{'sort':'talk_other','profile':'parent_b.jpg','content':'好的，老师！'},
		{'sort':'talk_other','profile':'parent_c.jpg','content':'收到！'},
		{'sort':'talk_other','profile':'parent_a.jpg','content':'收到！老师！'},
		{'sort':'talk_self','profile':'self.jpg','content':'好的'},
		{'sort':'talk_other','profile':'parent_e.jpg','content':'收到！'},
		{'sort':'talk_other','profile':'parent_f.jpg','content':'好的'},
		{'sort':'talk_other','profile':'parent_d.jpg','content':'收到'},
		{'sort':'talk_other','profile':'teacher_l.jpg','content':'@all 昨天和上午都通知过，最后一次强调一遍，今天会提前至5：30放学，请各位家长按时接小孩儿！'},
		{'sort':'talk_other','profile':'parent_g.jpg','content':'好的，老师'},
		{'sort':'talk_other','profile':'parent_h.jpg','content':'老师辛苦了！'},
		{'sort':'talk_other','profile':'parent_i.jpg','content':'收到！'},
		{'sort':'talk_other','profile':'parent_k.jpg','content':'收到，老师'},
		{'sort':'talk_other','profile':'parent_l.jpg','content':'收到，老师'},
		{'sort':'talk_self','profile':'self.jpg','content':'好的，下班就去。辛苦老师了'},
	];
	
	
	var talkZhao = [
		{'sort':'talk_other','profile':'teacher_z.jpg','content':'薇薇妈，今天薇薇在课堂上睡着了'},
		{'sort':'talk_self','profile':'self.jpg','content':'真的？可能没睡好吧'},
		{'sort':'talk_other','profile':'teacher_z.jpg','content':'薇薇妈，今天薇薇主动举手发言了'},
		{'sort':'talk_other','profile':'teacher_z.jpg','content':'而且孩子的口语技能也得到了提升'},
		{'sort':'talk_self','profile':'self.jpg','content':'谢谢老师夸奖'},
		{'sort':'talk_other','profile':'teacher_z.jpg','content':'薇薇妈，今天薇薇的作业完成的很好，值得表扬。'},
		{'sort':'talk_self','profile':'self.jpg','content':'谢谢老师的悉心指导和监督'},
		{'sort':'talk_other','profile':'teacher_z.jpg','content':'但是，孩子背单词的情况不是很乐观哈，还希望您能多监督一下'},
		{'sort':'talk_self','profile':'self.jpg','content':'好的，好的'},
		{'sort':'talk_other','profile':'teacher_z.jpg','content':'薇薇妈，昨天薇薇又迟到了，还请今天准时一些，多督促一下。'},
		{'sort':'talk_self','profile':'self.jpg','content':'不好意思啊老师，昨天孩子他爸工作耽误了一会儿，下次不会了'},
	];
		
	
	var talkBoss = [
		{'sort':'talk_self','profile':'self.jpg','content':'老板，明天孩子大扫除会提前放学，下午5:00～6:00请假一个小时'},
		{'sort':'talk_other','profile':'boss.jpg','content':'好的'},
		{'sort':'talk_other','profile':'boss.jpg','content':'上次新增的需求怎么没放到方案里？'},
		{'sort':'talk_self','profile':'self.jpg','content':'已经在做最后的检查了'},
		{'sort':'talk_other','profile':'boss.jpg','content':'刚刚客户提了新的创意，需要加进去'},
		{'sort':'talk_self','profile':'self.jpg','content':'老板，我昨天请过假了，需要提前去接小孩'},
		{'sort':'talk_other','profile':'boss.jpg','content':'那5点半能给到方案吗？'},
		{'sort':'talk_self','profile':'self.jpg','content':'好的，马上'},
		{'sort':'talk_other','profile':'boss.jpg','content':'<div class="talk_file"><h2>双十一企划案.pdf</h2><h3>1.14M</h3><h4 style="background-image: url(img/pdf.png);"></h4></div>'},
		{'sort':'talk_other','profile':'boss.jpg','content':'你周年庆的项目做得很好，这个双11的项目我想让你来做？有没有信心？ 可能需要外派出差，提前跟你家里说一下，做好准备。'},
		{'sort':'talk_self','profile':'self.jpg','content':'好的，谢谢老板信任！'},
	];
	
	
	var talkHusband = [
		{'sort':'talk_self','profile':'self.jpg','content':'今天几点能回来？'},
		{'sort':'talk_other','profile':'husband.jpg','content':'加班，不确定'},
		{'sort':'talk_self','profile':'self.jpg','content':'那我们还等不等你吃饭？'},
		{'sort':'talk_other','profile':'husband.jpg','content':'给我留点吧'},
		{'sort':'talk_self','profile':'self.jpg','content':'昨晚让你收衣服，你怎么不收完呀！'},
		{'sort':'talk_other','profile':'husband.jpg','content':'收完了啊'},
		{'sort':'talk_other','profile':'husband.jpg','content':'1.jpg','talk_sort':'look'},
		{'sort':'talk_self','profile':'self.jpg','content':'鞋子都没收，我早上一看，全淋湿了'},
		{'sort':'talk_other','profile':'husband.jpg','content':'好啦好啦，我以后注意'},
		{'sort':'talk_self','profile':'self.jpg','content':'2.jpg','talk_sort':'look'},
		{'sort':'talk_self','profile':'self.jpg','content':'晚上回来吃饭吗？'},
		{'sort':'talk_self','profile':'self.jpg','content':'老公，我今天加班，薇薇今天学校大扫除5:30之前去接孩子？'},
		{'sort':'talk_other','profile':'husband.jpg','content':'我咋去接啊？公司今天有应酬'},
		{'sort':'talk_self','profile':'self.jpg','content':'你怎么不早说？平常家里啥事不干，遇事还指望不上！孩子又不是我一个人生的，有你这么当爹的吗？'},
		{'sort':'talk_other','profile':'husband.jpg','content':'太忙没顾得上回微信，至于吗？'},
		{'sort':'talk_self','profile':'self.jpg','content':'算了，我让我妈去接吧'},
		{'sort':'talk_self','profile':'self.jpg','content':'<div class="talk_link"><h2>薇薇的画</h2><h3>专为7-12岁儿童设计的少儿绘画，只需99，5节课绘出缤纷世界</h3><h4 style="background-image: url(img/timg.jpg);"></h4></div>','talk_sort':'talk_self_link'},
		{'sort':'talk_self','profile':'self.jpg','content':'老公快看，女儿专门画给我的画！嫉妒吧！'},
		{'sort':'talk_other','profile':'husband.jpg','content':'都是薇薇妈教得好！'},
		{'sort':'talk_self','profile':'self.jpg','content':'那必须的！'},
	];
	
	
	var talkFriend = [
		{'sort':'talk_other','profile':'friend_b.jpg','content':'big.jpg','talk_sort':'look'},
		{'sort':'talk_other','profile':'friend_a.jpg','content':'又跑出去玩'},
		{'sort':'talk_other','profile':'friend_b.jpg','content':'是啊，我带宝宝出来玩'},
		{'sort':'talk_other','profile':'friend_a.jpg','content':'这是在哪儿啊'},
		{'sort':'talk_other','profile':'friend_b.jpg','content':'塞班岛啊！'},
		{'sort':'talk_other','profile':'friend_a.jpg','content':'还是你悠闲'},
		{'sort':'talk_other','profile':'friend_b.jpg','content':'妈妈多忙也得带孩子出来见见世面啊'},
		{'sort':'talk_other','profile':'friend_a.jpg','content':'嗯嗯，下周我和老公也要带孩子去海南玩玩了'},
		{'sort':'talk_other','profile':'friend_b.jpg','content':'海南啊！上次去海南晒伤了，注意给娃防晒啊'},
		{'sort':'talk_other','profile':'friend_a.jpg','content':'放心，早就买好了！'},
		{'sort':'talk_other','profile':'friend_b.jpg','content':'塞班岛还蛮舒服的'},
		{'sort':'talk_other','profile':'friend_a.jpg','content':'你回来做个攻略给我呗！'},
		{'sort':'talk_other','profile':'friend_b.jpg','content':'好哇！'},
		{'sort':'talk_self','profile':'self.jpg','content':'真棒！羡慕你们！'},
		{'sort':'talk_other','profile':'friend_b.jpg','content':'@Mrs李 要不要我在机场给你带点化妆品？上次看你皮肤状态特别不好。'},
		{'sort':'talk_self','profile':'self.jpg','content':'哈哈哈不用了，上次是没睡好，睡足就好了。'},
	];
	
	
	var talkChildren = [
		{'sort':'talk_other','profile':'children.jpg','content':'food.jpg','talk_sort':'look'},
		{'sort':'talk_other','profile':'children.jpg','content':'妈妈快去看，我给你写的小程序'},
		{'sort':'talk_self','profile':'self.jpg','content':'好的，妈妈马上去看'},
	];
	
	var talkMother = [
		{'sort':'talk_other','profile':'mother.jpg','content':'w1.jpg','talk_sort':'look'},
		{'sort':'talk_other','profile':'mother.jpg','content':'w2.jpg','talk_sort':'look'},
		{'sort':'talk_other','profile':'mother.jpg','content':'闺女，你爸今天下午一直咳嗽，你要是方便，下班路上能不能给买一点药，要是不方便，我明天再去药店买。'},
		{'sort':'talk_self','profile':'self.jpg','content':'我先买点药备着，周末抽空带爸去医院检查下。'},
	];
	
	gatherStyle();
	gatherList();
	addKeyboard();
	addTalk(talkParent,".talk_parent_");
	addTalk(talkZhao,".talk_zhao_");
	addTalk(talkBoss,".talk_boss_");
	addTalk(talkHusband,".talk_husband_");
	addTalk(talkFriend,".talk_friend_");
	addTalk(talkChildren,".talk_children_");
	addTalk(talkMother,".talk_mother_");
})

function addTalk(array,className){
	var array = array;
	var className = className;
	for(var i=0;i<array.length;i++){
		var thisData = array[i];
		var thisObj = $(className+i);
		var thisContent = thisData.content;
		var thisProfile = 'img/profile/'+thisData.profile;
		thisObj.addClass(thisData.sort);
		var thisLeft = "<dt style='background-image: url("+thisProfile+");'></dt>";
		var thisRight = "";
		if(thisData.talk_sort=='look'){ thisRight = "<dd class='talk_look'><img src='img/look/"+ thisContent +"' /></dd>"; }
		else if(thisData.talk_sort=='talk_self_link'){ thisRight = '<dd class="talk_self_link"><div class="talk_link"><h2>薇薇的画</h2><h3>专为7-12岁儿童设计的少儿绘画，只需99，5节课绘出缤纷世界</h3><h4 style="background-image: url(img/timg.jpg);"></h4></div></dd>'; }
		else{ thisRight = "<dd>"+ thisContent +"</dd>"; }
		var thisHtml = thisLeft + thisRight;
		thisObj.append(thisHtml);
	};
};

function addKeyboard(){
	$(".talk_bottom_box").append("<div class='keyboard'><div class='kother'><dl class='kother_1'><dd></dd></dl><dl class='kother_2'><dd></dd></dl><dl class='kother_3'><dd></dd></dl><dl class='kother_4'><dd></dd></dl><dl class='kother_5'><dd></dd></dl><dl class='kother_6'><dd></dd></dl><dl class='kother_7'><dd></dd></dl><dl class='kother_8'><dd></dd></dl></div><div class='kword'><dl class='kword_1'><dd></dd></dl><dl class='kword_2'><dd></dd></dl><dl class='kword_3'><dd></dd></dl><dl class='kword_4'><dd></dd></dl><dl class='kword_5'><dd></dd></dl><dl class='kword_6'><dd></dd></dl><dl class='kword_7'><dd></dd></dl><dl class='kword_8'><dd></dd></dl><dl class='kword_9'><dd></dd></dl></div><div class='ksend'><dl><dd></dd></dl></div></div>")
};

function gatherStyle(){
	$(".gather").append("<div class='gather_top'><dl>微信</dl></div><ul class='gather_bottom'><li class='on'><img src='img/gb_1.png' /><em>微信</em></li><li><img src='img/gb_2.png' /><em>通讯录</em></li><li><img src='img/gb_3.png' /><em>发现</em></li><li><img src='img/gb_4.png' /><em>我</em></li></ul>");
};

function gatherList(){
	var gatherList = [
		{'profile':'teacher_li','name':'舞蹈班李老师','summary':'好的，好的'},
		{'profile':'dad','name':'老爸','summary':'不忙就回来吃饭'},
		{'profile':'zhang','name':'客户张总','summary':'可以'},
		{'profile':'song','name':'宋天泽','summary':'嗯嗯'},
		{'profile':'yang','name':'杨玉银','summary':'好的'},
		{'profile':'zhao','name':'赵总','summary':'过来吧'}
	];
	for(var i=0;i<gatherList.length;i++){
		var thisData = gatherList[i];
		var thisProfile = thisData.profile;
		var thisName = thisData.name;
		var thisSummary = thisData.summary;
		$(".gather_list").append("<dl><dt style='background-image: url(img/profile/"+ thisProfile +".jpg);'></dt><dd><h2>"+ thisName +"</h2><h3>"+ thisSummary +"</h3></dd>");
	};
};

function total(timeDelay,timeDurat){
	for(var i=1;i<timeDelay.length;i++){
		timeDelay[i]=timeDelay[i]+timeDelay[i-1]+timeDurat[i-1];
	};
};

function addAnimate(timeDelay,timeDurat,layout){
	for(var i=1;i<timeDelay.length;i++){
		timeDelay[i]=timeDelay[i]+timeDelay[i-1]+timeDurat[i-1];
	};
	for(var i=0;i<layout.length;i++){
		$(layout[i]).css({
			"animation-delay":timeDelay[i]+"s",
			"animation-duration":timeDurat[i]+"s"
		});
	};
	page_total = timeDelay[timeDelay.length-1]+timeDurat[timeDurat.length-1];
	return page_total;
};

function keyBoardWrite(arr,pin,word){
	var arr = arr;
	var pin = pin;
	var word = word;
	
	for(var i=0;i<word.length;i++){
		var str = str+"<s><i>"+pin[i]+"</i></s>"+"<em>"+ word[i] +"</em>";
	};
	str = "<dl>"+str+"</dl>";	
		
	$(".talk_write").append(str);
	var arrchange = new Array();
	for(var i=0;i<arr.length;i++){
		if(i==0){
			arrchange[0] = arr[0]
		}
		else{
			arrchange[i]=arr[i]+arrchange[i-1];
		}
		$(".talk_write i").eq(i).css({
			"animation-delay":delay_1+(arrchange[i]-arr[i]/2)+"s"
		});
		$(".talk_write s").eq(i).css({
			"animation-delay":delay_1+arrchange[i]+"s"
		});
		$(".talk_write em").eq(i).css({
			"animation-delay":delay_1+arrchange[i]+"s"
		});
	}
	over_1 = delay_1 + .3
	delay_2 = over_1 + arrchange[arrchange.length - 1] 
	delay_3 = delay_2 + self_delay_3;
	delay_4 = delay_3 + self_delay_4;
	
	j=0;
	
	aaa=280;
	bbb=150;
	
	ccc=1000/aaa;
	print = setInterval(function(){
		if(j>(over_1-.4)*ccc){
			num = Math.floor(Math.random()*8)+1;
			$(".kword dl").eq(num).addClass("click");
			setTimeout(function(){
				$(".kword dl").eq(num).removeClass("click");
			},bbb)
		}
		if(j>(delay_2-.6)*ccc){
			clearInterval(print)
		}
		j++
	},aaa);
}

$(function(){
	$(".out").on('animationend', function(e) {
		obj = $(".talk_list_in");
		thisHeight = obj.height();
		parentHeight = obj.parents(".talk_list_out").height();
		if(thisHeight > parentHeight){
			obj.removeClass("talk_list_in_top");
		};
	});
});